<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QExtensionFactory Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QExtensionFactory Class Reference<br /><sup><sup>[<a href="qtdesigner.html">QtDesigner</a> module]</sup></sup></h1><p>The QExtensionFactory class allows you to create a factory that
is able to make instances of custom extensions in Qt Designer.
<a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a> and <a href="qabstractextensionfactory.html">QAbstractExtensionFactory</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qextensionfactory.html#QExtensionFactory">__init__</a></b> (<i>self</i>, QExtensionManager&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />QObject <b><a href="qextensionfactory.html#createExtension">createExtension</a></b> (<i>self</i>, QObject&#160;<i>object</i>, QString&#160;<i>iid</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" />QObject <b><a href="qextensionfactory.html#extension">extension</a></b> (<i>self</i>, QObject&#160;<i>object</i>, QString&#160;<i>iid</i>)</li><li><div class="fn" />QExtensionManager <b><a href="qextensionfactory.html#extensionManager">extensionManager</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QExtensionFactory class allows you to create a factory that
is able to make instances of custom extensions in Qt Designer.</p>
<p>In <i>Qt Designer</i> the extensions are not created until they
are required. For that reason, when implementing a custom
extension, you must also create a QExtensionFactory, i.e. a class
that is able to make an instance of your extension, and register it
using <i>Qt Designer</i>'s <a href="qextensionmanager.html">extension manager</a>.</p>
<p>The <a href="qextensionmanager.html">QExtensionManager</a> class
provides extension management facilities for Qt Designer. When an
extension is required, Qt Designer's <a href="qextensionmanager.html">extension manager</a> will run through all
its registered factories calling <a href="qextensionfactory.html#createExtension">QExtensionFactory.createExtension</a>()
for each until the first one that is able to create a requested
extension for the selected object, is found. This factory will then
make an instance of the extension.</p>
<p>There are four available types of extensions in Qt Designer:
<a href="qdesignercontainerextension.html">QDesignerContainerExtension</a>
, <a href="qdesignermembersheetextension.html">QDesignerMemberSheetExtension</a>,
<a href="qdesignerpropertysheetextension.html">QDesignerPropertySheetExtension</a>
and <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a>.
Qt Designer's behavior is the same whether the requested extension
is associated with a multi page container, a member sheet, a
property sheet or a task menu.</p>
<p>You can either create a new QExtensionFactory and reimplement
the <a href="qextensionfactory.html#createExtension">QExtensionFactory.createExtension</a>()
function. For example:</p>
<pre class="cpp">
         <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>ANewExtensionFactory<span class="operator">.</span><a href="qextensionfactory.html#createExtension">createExtension</a>(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>object<span class="operator">,</span>
                 <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent) <span class="keyword">const</span>
         {
             <span class="keyword">if</span> (iid <span class="operator">!</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>))
                 <span class="keyword">return</span> <span class="number">0</span>;

             <span class="keyword">if</span> (MyCustomWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MyCustomWidget<span class="operator">*</span><span class="operator">&gt;</span>
                    (object))
                 <span class="keyword">return</span> <span class="keyword">new</span> MyContainerExtension(widget<span class="operator">,</span> parent);

             <span class="keyword">return</span> <span class="number">0</span>;
         }
</pre>
<p>Or you can use an existing factory, expanding the <a href="qextensionfactory.html#createExtension">QExtensionFactory.createExtension</a>()
function to make the factory able to create your extension as well.
For example:</p>
<pre class="cpp">
         <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>AGeneralExtensionFactory<span class="operator">.</span><a href="qextensionfactory.html#createExtension">createExtension</a>(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>object<span class="operator">,</span>
                 <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span> <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent) <span class="keyword">const</span>
         {
             MyCustomWidget <span class="operator">*</span>widget <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span>MyCustomWidget<span class="operator">*</span><span class="operator">&gt;</span>(object);

             <span class="keyword">if</span> (widget <span class="operator">&amp;</span><span class="operator">&amp;</span> (iid <span class="operator">=</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a></span>))) {
                 <span class="keyword">return</span> <span class="keyword">new</span> MyTaskMenuExtension(widget<span class="operator">,</span> parent);

             } <span class="keyword">else</span> <span class="keyword">if</span> (widget <span class="operator">&amp;</span><span class="operator">&amp;</span> (iid <span class="operator">=</span><span class="operator">=</span> Q_TYPEID(<span class="type"><a href="qdesignercontainerextension.html">QDesignerContainerExtension</a></span>))) {
                 <span class="keyword">return</span> <span class="keyword">new</span> MyContainerExtension(widget<span class="operator">,</span> parent);

             } <span class="keyword">else</span> {
                 <span class="keyword">return</span> <span class="number">0</span>;
             }
         }
</pre>
<p>For a complete example using the QExtensionFactory class, see
the <a href="designer-taskmenuextension.html">Task Menu Extension
example</a>. The example shows how to create a custom widget plugin
for Qt Designer, and how to to use the <a href="qdesignertaskmenuextension.html">QDesignerTaskMenuExtension</a>
class to add custom items to Qt Designer's task menu.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QExtensionFactory" />QExtensionFactory.__init__ (<i>self</i>, <a href="qextensionmanager.html">QExtensionManager</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an extension factory with the given
<i>parent</i>.</p>


<h3 class="fn"><a name="createExtension" /><a href="qobject.html">QObject</a> QExtensionFactory.createExtension (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>object</i>, QString&#160;<i>iid</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Creates an extension specified by <i>iid</i> for the given
<i>object</i>. The extension object is created as a child of the
specified <i>parent</i>.</p>
<p><b>See also</b> <a href="qextensionfactory.html#extension">extension</a>().</p>


<h3 class="fn"><a name="extension" /><a href="qobject.html">QObject</a> QExtensionFactory.extension (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>object</i>, QString&#160;<i>iid</i>)</h3><p>Reimplemented from <a href="qabstractextensionfactory.html#extension">QAbstractExtensionFactory.extension</a>().</p>
<p>Returns the extension specified by <i>iid</i> for the given
<i>object</i>.</p>
<p><b>See also</b> <a href="qextensionfactory.html#createExtension">createExtension</a>().</p>


<h3 class="fn"><a name="extensionManager" /><a href="qextensionmanager.html">QExtensionManager</a> QExtensionFactory.extensionManager (<i>self</i>)</h3><p>Returns the extension manager for the extension factory.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>